package com.hjm.project.agentInfo.point.controller;

import java.util.List;
import java.util.Map;

import com.hjm.project.agentInfo.point.domain.TaxPoint;
import com.hjm.project.agentInfo.point.service.ITaxPointService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 服务商税点信息Controller
 * 
 * @author LOVE
 * @date 2020-12-03
 */
@Controller
@RequestMapping("/agentInfo/point")
public class TaxPointController extends BaseController
{
    private String prefix = "agentInfo/point";

    @Autowired
    private ITaxPointService taxPointService;

    @RequiresPermissions("agentInfo:point:view")
    @GetMapping()
    public String point()
    {
        return prefix + "/point";
    }

    /**
     * 查询服务商税点信息列表
     */
    @RequiresPermissions("agentInfo:point:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TaxPoint taxPoint)
    {
        startPage();
        List<TaxPoint> list = taxPointService.selectTaxPointList(taxPoint);
        return getDataTable(list);
    }

    /**
     * 导出服务商税点信息列表
     */
    @RequiresPermissions("agentInfo:point:export")
    @Log(title = "服务商税点信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TaxPoint taxPoint)
    {
        List<TaxPoint> list = taxPointService.selectTaxPointList(taxPoint);
        ExcelUtil<TaxPoint> util = new ExcelUtil<TaxPoint>(TaxPoint.class);
        return util.exportExcel(list, "point");
    }

    /**
     * 新增服务商税点信息
     */
    @GetMapping("/add")
    public String add(String agentNum, Map mmp)
    {
        mmp.put("agentNum",agentNum);
        return prefix + "/add";
    }

    /**
     * 新增保存服务商税点信息
     */
    @Log(title = "服务商税点信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TaxPoint taxPoint)
    {
        Map<String, String> map = taxPointService.insertTaxPoint(taxPoint);
        if ("00".equals(map.get("code"))) {
            return AjaxResult.success();
        } else {
            return AjaxResult.warn(map.get("msg"));
        }
    }

    /**
     * 修改服务商税点信息
     */
    @GetMapping("/edit/{tpNum}")
    public String edit(@PathVariable("tpNum") Long tpNum, ModelMap mmap)
    {
        TaxPoint taxPoint = taxPointService.selectTaxPointById(tpNum);
        mmap.put("taxPoint", taxPoint);
        return prefix + "/edit";
    }

    /**
     * 修改保存服务商税点信息
     */
    @Log(title = "服务商税点信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TaxPoint taxPoint)
    {
        Map<String, String> map = taxPointService.updateTaxPoint(taxPoint);
        if ("00".equals(map.get("code"))) {
            return AjaxResult.success();
        } else {
            return AjaxResult.warn(map.get("msg"));
        }
    }

    /**
     * 删除服务商税点信息
     */
    @RequiresPermissions("agentInfo:point:remove")
    @Log(title = "服务商税点信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(taxPointService.deleteTaxPointByIds(ids));
    }
}
